﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interfleet.SE.UICompiler.Core.YahooJavaScriptCompressor
{
    /// <summary>
    /// Result builder for the Yahoo Javascript Compressor.
    /// </summary>
    public class YJResultBuilder : ResultBuilder
    {
        internal YJResultBuilder(Arguments arguments)
            : this(arguments, new FileProvider())
        {

        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments">Arguments used for compilation</param>
        /// <param name="fileInfoProvider">A <see cref="IFileProvider"/></param>
        public YJResultBuilder(Arguments arguments, IFileProvider fileInfoProvider)
            : base(arguments, fileInfoProvider)
        {
            
        }
    
        /// <summary>
        /// Builds up a <see cref="CompileResult"/>
        /// </summary>
        /// <param name="jsResult">Result of compilation</param>
        /// <param name="compilationStartedAt">Timestamp representing start time of the compilation</param>
        /// <returns>A <see cref="CompileResult"/></returns>
        public override CompileResult  Build(string jsResult, DateTime compilationStartedAt)
        {
            var result = new CompileResult(Arguments.Files, Arguments.CompiledFileName);
            FileInfoProvider.SaveToFile(Arguments.CompiledFileName, jsResult);
            result.Success = true;
            result.StatusMessage = string.Concat("Compiled file: ", Arguments.CompiledFileName);
            return result;
        }
    }
}
